/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session;

import entity.JobStatus;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author owtee
 */
@Stateless
public class JobStatusFacade extends AbstractFacade<JobStatus> {

    @PersistenceContext(unitName = "MSGPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public JobStatusFacade() {
        super(JobStatus.class);
    }

    public List<JobStatus> findByIdAndName(String statusId, String statusName) {
        em.getEntityManagerFactory().getCache().evictAll();
        return em.createQuery("SELECT j FROM JobStatus j WHERE j.statusId LIKE :statusId AND j.statusName LIKE :statusName")
                .setParameter("statusId", statusId)
                .setParameter("statusName", statusName)
                .getResultList();
    }

    public List<JobStatus> findByIdAndName(int start, int end, String statusId, String statusName) {
        em.getEntityManagerFactory().getCache().evictAll();
        return em.createQuery("SELECT j FROM JobStatus j WHERE j.statusId LIKE :statusId AND j.statusName LIKE :statusName")
                .setFirstResult(start)
                .setMaxResults(end)
                .setParameter("statusId", statusId)
                .setParameter("statusName", statusName)
                .getResultList();
    }
}
